﻿#include "AboutDialog.h"
#include "ui_AboutDialog.h"
#include "HistoryChangesDialog.h"
#include "global/const.h"
#include "stores/StoreFilePath.h"
#include "stores/DataStroes.h"
#include "utils/String/version.h"

#include <QProcess>


AboutDialog::AboutDialog(QWidget *parent)
    : FDialog(parent)
    , ui(new Ui::AboutDialog)
{
    ui->setupUi(this);
    setWindowFlag(Qt::WindowContextHelpButtonHint, false);
    setWindowTitle(tr("About"));

    ui->labelAppName->setText(APP_NAME);

    const QString& versionString = Version::ver2str(APP_VERSION);

    ui->labelVersion->setText(versionString);

    auto& releaseNotes = DataStroes::instance()->releaseNotes()->model();
    if (releaseNotes.isValid() && releaseNotes.data().notes.length() > 0) {
        auto& note = releaseNotes.data().notes[0];
        ui->lwChanges->addItem(tr("Release Date: %1").arg(note.date));
        ui->lwChanges->addItem(tr("Changes:"));
        int i = 1;
        for (const QString& change : note.changes) {
            ui->lwChanges->addItem(QString("%1. %2").arg(i++, 2).arg(change));
        }
    }
}

AboutDialog::~AboutDialog()
{
    delete ui;
}

void AboutDialog::on_btnCheckUpdate_clicked()
{
    QProcess::startDetached(StoreFilePath::updateAppFilePath());
}

void AboutDialog::on_btnHistoryChanges_clicked()
{
    HistoryChangesDialog(this).exec();
}

